home *** CD-ROM | disk | FTP | other *** search
- {$N-} {Much Better with $N+}
- Program Bounce;
-
- Uses WinProcs, WinTypes, WObjects;
-
- Type
- PBounceWnd = ^TBounceWnd;
- TBounceWnd = Object(TWindow)
- hBallBitMap : hBitMap;
- hdcMem : hDC;
- hMyBrush : hBrush;
- TheDC : hDC;
- cxClient,
- cyClient : Word;
- xPixel,
- yPixel : Integer;
- xCenter,
- yCenter : Integer;
- cxTotal,
- cyTotal : Integer;
- cxRadius,
- cyRadius : Integer;
- cxMove,
- cyMove : Integer;
-
- nScale : Integer;
-
- Constructor Init(AParent : PWindowsObject; ATitle : PChar);
- Procedure WMCreate(Var Msg : TMessage);
- Virtual wm_First + wm_Create;
- Procedure WMDestroy(Var Msg : TMessage);
- Virtual wm_First + wm_Destroy;
- Procedure WMSize(Var Msg : TMessage);
- Virtual wm_First + wm_Size;
- Procedure WMTimer(Var Msg : TMessage);
- Virtual wm_First + wm_Timer;
- End;
-
- TBounceApp = Object(TApplication)
- Procedure InitMainWindow; Virtual;
- End;
-
- Constructor TBounceWnd.Init(AParent :PWindowsObject; ATitle : PChar);
-
- Begin
- TWindow.Init(AParent, ATitle);
- End;
-
- Procedure TBounceWnd.WMCreate(Var Msg : TMessage);
- Begin
- TWindow.WMCreate(Msg);
- If Not Boolean(SetTimer(hWindow, 1, 75, nil)) Then
- Begin
- MessageBox(hWindow, 'Couldn''t Init Timer', 'Bounce',
- MB_IconExclamation or mb_Ok);
- Done;
- End;
- TheDC := GetDC(hWindow);
- If TheDC = 0 Then
- Begin
- MessageBox(hWindow, 'We didn''t get the DC', 'Create', mb_Ok);
- Done;
- End;
- xPixel := GetDeviceCaps(TheDC, AspectX);
- yPixel := GetDeviceCaps(TheDC, AspectY);
- ReleaseDC(hWindow, TheDC);
- End;
-
- Procedure TBounceWnd.WMDestroy(Var Msg : TMessage);
- Begin
- if hBallBitMap <> 0 Then DeleteObject(hBallBitMap);
- KillTimer(hWindow, 1);
- TWindow.WMDestroy(Msg);
- End;
-
- Procedure TBounceWnd.WMSize(Var Msg : TMessage);
-
- Begin
- cxClient := LoWord(Msg.lParam);
- cyClient := HiWord(Msg.lParam);
- xCenter := cxClient div 2;
- yCenter := cyClient div 2;
- If (cxClient * xPixel) < (cyClient * yPixel) Then
- nScale := (cxClient * xPixel) div 16
- Else nScale := (cyClient * yPixel) div 16;
- cxRadius := nScale div xPixel;
- cyRadius := nScale div yPixel;
- If (cxRadius div 4) > 1 Then cxMove := cxRadius div 4
- Else cxMove := 1;
- If (cyRadius div 4) > 1 Then cyMove := cyRadius div 4
- Else cyMove := 1;
- cxTotal := 2 * (cxRadius + cxMove);
- cyTotal := 2 * (cyRadius + cyMove);
-
- If hBallBitMap <> 0 Then DeleteObject(hBallBitMap);
-
- TheDC := GetDC(hWindow);
- hDCMem := CreateCompatibleDC(TheDC);
- hBallBitMap := CreateCompatibleBitMap(TheDC, cxTotal, cyTotal);
- ReleaseDC(hWindow, TheDC);
-
- SelectObject(hdcMem, hBallBitMap);
- Rectangle(hdcMem, -1, -1, cxTotal + 1, cyTotal +1);
-
- hMyBrush := CreateHatchBrush(HS_DiagCross, LongInt(0));
- SelectObject(hdcMem, hMyBrush);
- SetBkColor(hdcMem, RGB(255,0,255));
-
- Ellipse(hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove);
-
- DeleteDC(hdcMem);
- DeleteObject(hMyBrush);
-
- { TWindow.WMSize(Msg);
- }
- End;
-
- Procedure TBounceWnd.WMTimer(Var Msg : TMessage);
-
- Begin
- If hBallBitMap <> 0 Then
- Begin
- {
- MessageBeep(10);
- }
- TheDC := GetDC(hWindow);
- hdcMem := CreateCompatibleDC(TheDC);
- SelectObject(hdcMem, hBallBitMap);
- BitBlt(TheDC, xCenter - cxTotal div 2, yCenter - cyTotal div 2,
- cxTotal, cyTotal, hdcMem, 0, 0, SrcCopy);
-
- ReleaseDC(hWindow, TheDC);
- DeleteDC(hdcMem);
-
- Inc(xCenter, cxMove);
- Inc(yCenter, cyMove);
- If ((xCenter + cxRadius >= cxClient) or (xCenter - cxRadius <=0)) Then
- cxMove := cxMove * (-1);
- If ((yCenter + cyRadius >= cyClient) or (yCenter - cyRadius <=0)) Then
- cyMove := cyMove * (-1);
-
- End;
- End;
-
- Procedure TBounceApp.InitMainWindow;
- Begin
- MainWindow := New(PBounceWnd, Init(Nil, 'Draw A Bounce'));
- End;
-
- Var BounceApp : TBounceApp;
-
- Begin
- BounceApp.Init('Bounce');
- BounceApp.Run;
- BounceApp.Done;
- End.